<?php
$q1 = "SELECT proxy, port FROM `proxy_check` WHERE (vk=1 AND code=200) GROUP BY proxy ASC LIMIT 3";
$i1 = 0;
$i2 = 0;

$dbcnx = @mysql_connect("localhost", "root", "qqq");
mysql_query("SET NAMES utf8");
@mysql_select_db("vknew", $dbcnx);

$result = mysql_query($q1);
while($row = mysql_fetch_row($result)) {
	list($v1[$i1]['proxy'], $v1[$i1]['port']) = $row;
	$i1++;
}


for($i1 = 0; $i1 < count($v1); $i1++) {
	echo $i1." ".$v1[$i1]['proxy'].":".$v1[$i1]['port']."\n";
	$q2  = "SELECT proxy, port, time, check_time FROM `proxy_check`";
	$q2 .=" WHERE proxy='".$v1[$i1]['proxy']."' AND vk=0";
	$result = mysql_query($q2);
	$i2 = 0;
	while($row = mysql_fetch_row($result)) {
		list($v2[$i1][$i2]['proxy'],
		/* */$v2[$i1][$i2]['port'],
		/* */$v2[$i1][$i2]['time'],
		/* */$v2[$i1][$i2]['check_time']) = $row;
		$i2++;
	}
}
mysql_close($dbcnx);

for($i1 = 0; $i1 < count($v1); $i1++) {
	$v2_tt[$i1] = 0;
	for($i2 = 0; $i2 < count($v2[$i1]); $i2++) {
		echo $i2." ".       $v2[$i1][$i2]['proxy'];
		echo ":".           $v2[$i1][$i2]['port'];
		echo " time=".      $v2[$i1][$i2]['time'];
		echo " check_time=".$v2[$i1][$i2]['check_time']."\n";
		$v2_tt[$i1] += $v2[$i1][$i2]['time']; # total time
	}
}

//print_r($v2[130]);
print_r($v2_tt);
?>